﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Manso.cBot.Common
{
    /// <summary>
    /// This class manage all commands available on cBot. In normal scenario you dont need to use this class.
    /// </summary>
    public class CommandManager
    {
        private readonly Dictionary<String, ICommand> _commands;

        public CommandManager()
        {
            _commands = new Dictionary<string, ICommand>();
        }

        public void AddCommand(ICommand command)
        {
            _commands.Add(command.Command.ToLower(), command);
        }

        public ICommand GetCommand(String command, ListenToEnum listenTo)
        {
            if (_commands.ContainsKey(command.ToLower()) && 
                (_commands[command.ToLower()].ListenTo == listenTo || _commands[command.ToLower()].ListenTo == ListenToEnum.Both))
            {
                return _commands[command.ToLower()];
            }
            else
            {
                return null;
            }
        }       

        public void RemoveCommand(ICommand command)
        {
            _commands.Remove(command.Command.ToLower());
        }

        public bool Contains(ICommand command)
        {
            return _commands.ContainsKey(command.Command.ToLower());
        }
    }
}